package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/13.<br><br>
 *
 * 3的幂
 */
public class Topic326 {
    public static void main(String[] args) {
       Topic326 instance = new Topic326();

        System.out.println(instance.isPowerOfThree(27));
        System.out.println(instance.isPowerOfThree(81));
        System.out.println(instance.isPowerOfThree(0));
        System.out.println(instance.isPowerOfThree(9));
        System.out.println(instance.isPowerOfThree(45));
    }

    public boolean isPowerOfThree(int n) {
        if(n < 1) {
            return false;
        }

        if(n == 1) {
            return true;
        }

        while (n != 1) {
            if(n % 3 != 0) {
                return false;
            }

            n = n / 3;
        }

        return true;
    }
}
